package com.group3.controller.teacherController;

import com.group3.domain.Work;
import com.group3.pojo.Page;
import com.group3.pojo.receive.ReplyWorkReceive;
import com.group3.pojo.receive.TAddWorkReceive;
import com.group3.pojo.receive.TStudentWorkReceive;
import com.group3.service.TeacherWorkManageService;
import com.group3.pojo.result.StudentWorkResult;
import com.group3.service.StudentWorkService;
import com.group3.utils.Result;
import com.group3.pojo.StudentWork;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName WorkmanageController - 作业管理界面
 * @Author jt-sinlio,PX
 * @Time 2021/6/3 16:34
 **/

@Api(tags = "教师接口")
@RestController
@RequestMapping("/teacher/work")
public class TeacherWorkManageController {
    @Resource
    TeacherWorkManageService workManageService;
    @Resource
    private TeacherWorkManageService teacherWorkManageService;
    //=====================下发作业 界面================================

    // 查询教师下发作业列表
    @ApiOperation(value = "查询作业列表")
    @GetMapping("")
    public Result<List<StudentWorkResult>> selectStudentWork(
            TStudentWorkReceive tStudentWorkReceive, HttpServletRequest request) {
        String token = request.getHeader("token");//获取token
        Result result = workManageService.selectStudentWork(tStudentWorkReceive, token);

        return result;
    }

    // 查看单个作业详情
    @ApiOperation(value = "查看单个作业详情")
    @GetMapping("/resource")
    @ApiImplicitParam(name = "workId", value = "作业ID", required = true,
            dataType = "int")
    public Result<TAddWorkReceive> showWork(Integer workId) {

        Result result = teacherWorkManageService.showWork(workId);
        return result;
    }

    //增加作业
    @ApiOperation(value = "老师发布作业")
    @PutMapping("")
    public Result addWork(TAddWorkReceive tAddWorkReceive) {
        Result result = teacherWorkManageService.addWork(tAddWorkReceive);
        return result;
    }

    // 教师修改已发布作业的题目、时间等
    @ApiOperation(value = "教师修改已发布作业")
    @PostMapping("")
    public Result updateWork(Work work) {
        Result result = teacherWorkManageService.updateWork(work);
        return result;
    }

    // 教师删除作业
    @ApiOperation(value = "删除作业")
    @DeleteMapping("/workId")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "workId", value = "作业ID", required = true,
//                    dataType = "Integer")
//    })
    public Result deleteWork(@PathVariable Integer workId) {

        return teacherWorkManageService.deleteWork(workId);
    }


    //=====================作业审批================================

    //---------------------待批复----------------------------------

    // 查询已提交作业列表
    @ApiOperation(value = "查询已提交、待批复作业列表")
    @GetMapping("/finished")
    public Result<StudentWork> selectFinishedWork(TStudentWorkReceive tStudentWorkReceive, HttpServletRequest request) {
        String token = request.getHeader("token");//获取token
        Result result = teacherWorkManageService.selectStudentWork(tStudentWorkReceive, token);

        return result;
    }

    //教师批改已提交作业
    @ApiOperation(value = "教师批改已提交作业")
    @PutMapping("/reply")

    public Result reply(ReplyWorkReceive replyWorkReceive) {

        Result result = teacherWorkManageService.reply(replyWorkReceive);

        return result;
    }
}